<script setup lang="ts">
import { saveUserPlanCOnfig } from '@/api/login/AuthApi';
import { showSuccessToast, showFailToast } from 'vant';
import { ref } from 'vue';
let key = ref("");
let showPicker = ref(false);
let content = ref("")
let name = ref("");
const onConfirm = (selectObject: { selectedOptions: any[]; selectedValues: any[]; }) => {
    let selectOption = selectObject.selectedOptions[0];
    let value = selectObject.selectedValues[0];
    let storageKey = mapDict(value);
    name.value = selectOption?.text;
    if (storageKey) {
        var text = localStorage.getItem(storageKey) ?? "";
        content.value = text;
        key.value = storageKey;
    }

    showPicker.value = false;

};
const columns = [
    { text: '编译计划1.0', value: 'Boss1' },
    { text: '编译计划2.0', value: 'Boss2' },
    { text: '编译计划3.0', value: 'Boss3' },
    { text: '编译计划4.0', value: 'Boss4' },
    { text: '编译计划5.0', value: 'Boss5' },
    { text: '编译计划6.0', value: 'Boss6' },
];
const mapDict = (tkey: string) => {
    let mkey = "";
    switch (tkey) {
        case "Boss1":
            mkey = "BossRecmStrategy";
            break;
        case "Boss2":
            mkey = "BossRecmStrategyV2";
            break;
        case "Boss3":
            mkey = "BossRecmStrategyV3NewVersion";
            break;
        case "Boss4":
            mkey = "BossRecmStrategyV4";
            break;
        case "Boss5":
            mkey = "BossRecmStrategyV5";
            break;
        case "Boss6":
            mkey = "BossRecmStrategyV6";
            break;
        default:
            showFailToast("暂不支持")
            break;

    }
    return mkey;
}
const submitToServer = async () => {
    if (key.value && content.value) {
        await saveUserPlanCOnfig(key.value, content.value, name.value);
    }
    else {
        showFailToast("请选择需要上传的配置");
    }

}
</script>
<template>
    <van-cell-group inset>
        <van-field v-model="key" is-link readonly label="Key" placeholder="选择需要加载的Key" @click="showPicker = true" />
        <van-popup v-model:show="showPicker" round position="bottom">
            <van-picker :columns="columns" @cancel="showPicker = false" @confirm="onConfirm" />
        </van-popup>
        <van-field v-model="content" rows="1" :autosize="{ maxHeight: 450, minHeight: 50 }" label="value" readonly
            type="textarea" />
    </van-cell-group>
    <div style="margin: 16px;">
        <van-button round block type="primary" native-type="submit" @click="submitToServer">
            上传服务器
        </van-button>
    </div>
</template>